﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    public DateTime DT
    {
        get { return string.IsNullOrEmpty(HiddenField_LastDate.Value) ? DateTime.MinValue : Convert.ToDateTime(HiddenField_LastDate.Value); }
    }


    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        DateTime dt = DT;

        if (dt == DateTime.MinValue || dt == null)
        {
            this.TextBox_Start.Text = Calendar1.SelectedDate > DateTime.Now ? DateTime.Now.ToString() : Calendar1.SelectedDate.ToString();

            this.TextBox_End.Text = dt > DateTime.Now ? Calendar1.SelectedDate.ToString() : DateTime.Now.ToString();
        }
        else
        {
            this.TextBox_Start.Text = Calendar1.SelectedDate > dt ? dt.ToString() : Calendar1.SelectedDate.ToString();

            this.TextBox_End.Text = Calendar1.SelectedDate > dt ? Calendar1.SelectedDate.ToString() : dt.ToString();
        }
        HiddenField_LastDate.Value = Calendar1.SelectedDate.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <div> 
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
            BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" 
            DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
            ForeColor="#003399" Height="200px" 
            onselectionchanged="Calendar1_SelectionChanged" Width="220px" >
            <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
            <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
            <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" 
                Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
            <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
            <WeekendDayStyle BackColor="#CCCCFF" />
        </asp:Calendar>
        shi<asp:TextBox ID="TextBox_Start" Enabled="false" runat="server"></asp:TextBox>
        zhong
        <asp:TextBox ID="TextBox_End" Enabled="false" runat="server"></asp:TextBox> 
        <asp:HiddenField ID="HiddenField_LastDate" runat="server" /> 
    </div>
    </div>
    </form>
</body>
</html>
